/**
 * 
 */
package cre.jaxws.publish;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.cxf.transport.http.HTTPTransportFactory;

import cre.order.HelloWorld;
import cre.order.HelloWorldImpl;

/**
 * @author Cre.Gu
 *
 */
public class ServerPublish2 {

	public static void main(String[] args) throws InterruptedException {

		Bus bus = BusFactory.getDefaultBus();
		DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);

		HTTPTransportFactory httpTransportFactory = new HTTPTransportFactory();

		dfm.registerDestinationFactory("test", httpTransportFactory);

		HelloWorldImpl implementor = new HelloWorldImpl();
		JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
		svrFactory.setServiceClass(HelloWorld.class);
		svrFactory.setAddress("local://helloWorld");
		svrFactory.setServiceBean(implementor);
		svrFactory.getInInterceptors().add(new LoggingInInterceptor());
		svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());

		svrFactory.create();

		Thread.sleep(5 * 60 * 1000);
		System.out.println("Server exiting");
		System.exit(0);
	}
}
